package 不同数组结合;

//随机5位验证码
public class text1 {
    public static void main(String[] args) {

//        char a = 97;//char类型的97，ascll码是小写字母a
//        System.out.println(a);

        char[] arr1 = new char[26];
        char[] arr2 = new char[26];
        int[] arr3 = new int[10];
        Object[] arr0 = new Object[52]; //Object数据类型可以存储多个不同数据类型的数组

        //小写字母
        arr1 = arr1(arr1);
        //大写字母
        arr2 = arr2(arr2);
        //0-9数字
        arr3 = arr3(arr3);

/*      //将两个char类型的数组结合在一起
        arr0=togeher(arr1,arr2);
        print1(arr0);
        print1(arr3);
*/
        //将三个不同数据类型的数组结合在一起
        arr0 = togeher(arr1, arr2, arr3);
        print1(arr0);


/*      //用自定义大方法输出三个数组
        print1(arr1);
        print1(arr2);
        print1(arr3);*/


/*      //用for循环方法分别输出三个数组
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i]+" ");
        }
        System.out.println("\n");

        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i]+" ");
        }
        System.out.println("\n");

        for (int i = 0; i < arr3.length; i++) {
            System.out.print(arr3[i]+" ");
        }
*/
    }

    //生成26个小写字母
    public static char[] arr1(char[] arr1) {
        for (int i = 0; i < arr1.length; i++) {
            char a1 = (char) (i + 97);
            arr1[i] = a1;
        }
        return arr1;
    }

    //    生成26个大写字母
    public static char[] arr2(char[] arr2) {
        for (int i = 0; i < arr2.length; i++) {
            char a1 = (char) (i + 65);
            arr2[i] = a1;
        }
        return arr2;
    }

    //    生成数字
    public static int[] arr3(int[] arr3) {
        for (int i = 0; i < arr3.length; i++) {
            arr3[i] = i;
        }
        return arr3;
    }

    //    打印数组，使用了方法的重载（即同方法名不同形参）
    public static void print1(char[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("\n");
    }

    public static void print1(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("\n");
    }

    public static void print1(Object[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("\n");
    }

    //    将两个char类型的数组组合在一起
    public static char[] togeher(char[] a, char[] b) {
        int size = a.length + b.length;
        char[] arr = new char[size];
        for (int i = 0; i < arr.length; i++) {
            if (i < a.length) {
                arr[i] = a[i];
            } else {
                arr[i] = b[i - a.length];
            }
        }
        return arr;
    }

    //    Object:将三个不同数据类型的数组组合在一起
    public static Object[] togeher(char[] a, char[] b, int[] c) {
        int size = a.length + b.length + c.length;
        Object[] arr = new Object[size];
        for (int i = 0; i < arr.length; i++) {
            if (i < a.length) {
                arr[i] = a[i];
            } else if (i >= a.length && i < a.length + b.length) {
                arr[i] = b[i - a.length];
            } else {
                arr[i] = c[i - a.length - b.length];
            }
        }
        return arr;
    }
}
